package com.zmytest.many2one;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created on 2018/12/24.
 *
 * @author zhangmingyu
 */
@RestController
@RequestMapping("/many2one")
public class Test3Controller {

    @Autowired
    private GroupRepository groupRepository;
    @Autowired
    private MemberRepository memberRepository;


    @GetMapping("/create")
    public void test(){
        Group group = new Group();
        group.setName("hello");
        Group g = groupRepository.saveAndFlush(group);

        Member member = new Member();
//        member.setName("zmytest");
//        Group gtemp = new Group();
//        gtemp.setId(1);
//        member.setGroup(gtemp);
        member.setGroup(g);
        Member result = memberRepository.saveAndFlush(member);

        System.out.println("result "+result);
    }
}
